package com.treasure.mall.biz.repository.auction;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.auction.AuctionSessionPO;
import com.treasure.mall.zbq.common.ienum.auction.AuctionEnums;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/7/16
 */
@Repository
public interface AuctionSessionRepository extends JpaSearchableRepository<AuctionSessionPO, Long> {
    /**
     * 得到最新一次的拍卖
     *
     * @param productId
     * @return
     */
    AuctionSessionPO findTopByProductPO_ProductIdOrderByCreateTimeDesc(Long productId);

    List<AuctionSessionPO> findByStartTimeGreaterThanEqual(LocalDateTime time);

    List<AuctionSessionPO> findByAuctionStatusAndEndTimeGreaterThanEqual(AuctionEnums.AuctionStatus auctionStatus, LocalDateTime time);

    /**
     * @param auctionStatus
     * @param time
     * @return
     */
    List<AuctionSessionPO> findByAuctionStatusAndEndTimeLessThanEqual(AuctionEnums.AuctionStatus auctionStatus, LocalDateTime time);

    /**
     * 获取所有未开拍的数据
     *
     * @param auctionStatus
     * @return
     */
    List<AuctionSessionPO> findByAuctionStatus(AuctionEnums.AuctionStatus auctionStatus);

    /**
     * 根据房间ID，获取所有未结束的拍卖数据
     *
     * @param roomId
     * @return
     */
    @Query("select  po from AuctionSessionPO  po where po.roomId=?1 and po.auctionStatus <> ?2 ")
    List<AuctionSessionPO> findByRoomIdNotAndAuctionStatus(Long roomId, AuctionEnums.AuctionStatus auctionStatus);
}
